package com.ler.yrmall.ware.rpc;

import com.ler.yrmall.ware.service.WareSkuService;
import com.ler.yrmall.ware.api.WareApi;
import com.ler.yrmall.ware.dto.WareLockDTO;
import com.ler.yrmall.basic.Result;
import lombok.Data;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Leron
 * @version 1.0
 */
@DubboService
public class WareApiImpl implements WareApi {

    @Resource
    private WareSkuService wareSkuService;

    @Override
    public Result<Map<Long, Boolean>> hasStork(List<Long> skuIds) {
        Map<Long, Boolean> res = wareSkuService.hasStockBySkuIds(skuIds);
        return Result.ok(res);
    }

    @Override
    public Result<?> orderLock(WareLockDTO wareLock) {
        Result<?> result = new Result<>();
        result.setSuccess(wareSkuService.orderLock(wareLock));
        return result;
    }

    @Data
    static class SkuWareHasStock {

        private Long skuId;

        private Integer num;

        private List<Long> wareIds;
    }
}
